package ${controllerPackageName};


import cn.kawins.base.result.ResultBody;
import com.github.pagehelper.PageInfo;
import ${servicePackageName}.${serviceName};
import ${entityPackageName}.${entityName};
import ${dtoPackageName}.${dtoName};
import ${voPackageName}.${voName};
import ${convertPackageName}.${convertName};

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;
import javax.validation.Valid;
import java.util.List;

import java.io.Serializable;
import java.util.List;

/**
*  controller
*
* @ClassName: ${controllerName}
* @Description: 控制层访问接口
* @author ${authorName}
* @date ${currentTime}
*/
@Api(tags="${tabInfo.tableComment}接口管理")
@RestController
@AllArgsConstructor
@RequestMapping("/${moduleName?lower_case}/${entityName?uncap_first}")
public class ${controllerName}  {
    <#assign serviceVariable='${serviceName?uncap_first}'>
    private final  ${serviceName} ${serviceVariable};

    @PostMapping({"/page"})
    @ApiOperation(value = "分页")
    public ResultBody page(@RequestBody ${dtoName} query){
        PageInfo<${voName}> page = ${serviceVariable}.page(query);

        return ResultBody.success(page);
    }

    @GetMapping({"/list"})
    @ApiOperation(value = "获取列表")
    public ResultBody list(${dtoName} query){
        List<${voName}> list=${serviceVariable}.listByDTO(query);

        return ResultBody.success(list);
    }

    @GetMapping("{id}")
    @ApiOperation(value = "获取信息")
    public ResultBody get(@PathVariable("id") Long id){
        ${entityName} entity = ${serviceVariable}.selectById(id);

        return ResultBody.success(${convertName}.INSTANCE.convert(entity));
    }

    @PostMapping({"/save"})
    @ApiOperation(value = "保存")
    public ResultBody save(@RequestBody ${voName} vo){
        ${serviceVariable}.save(vo);
        return ResultBody.success();
    }

    @PutMapping({"/update"})
    @ApiOperation(value = "修改")
    public ResultBody update(@RequestBody ${voName} vo){
        ${entityName} entity = ${serviceVariable}.update(vo);
        return (entity != null) ? ResultBody.success(entity) : ResultBody.failed("更新失败");
    }

    @DeleteMapping({"/delete"})
    @ApiOperation(value = "删除")
    public ResultBody delete(@RequestBody List<Long> idList){
        ${serviceVariable}.delete(idList);

        return ResultBody.success();
    }

}